//package com.ruoyi.common.DataConversion.service.Impl;
//
//import com.sxygsj.mapper.CardInfoMapper;
//import com.sxygsj.mapper.CardReaderMapper;
//import com.sxygsj.mapper.DownStationInfoMapper;
//import com.sxygsj.mapper.StationInfoMapper;
//import com.sxygsj.task.ProtocolAnalysis;
//import com.sxygsj.common.MainObject;
//import com.sxygsj.protocols.*;
//import com.sxygsj.service.DownStationInfoService;
//import com.sxygsj.utils.NumberUtils;
//import com.sxygsj.utils.StringUtils;
//import com.sxygsj.utils.TypeConvertUtils;
//import org.apache.logging.log4j.LogManager;
//import org.apache.logging.log4j.Logger;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import struct.JavaStruct;
//
//import java.net.Socket;
//import java.nio.ByteOrder;
//import java.text.DecimalFormat;
//import java.text.SimpleDateFormat;
//import java.util.*;
//import java.util.concurrent.Callable;
//import java.util.concurrent.FutureTask;
//import java.util.stream.Collectors;
//
///**
// * @ClassName DownStationInfoServiceImpl
// * @Description 分站信息下发服务实现
// * @Author 张永永
// * @Date 2020-12-26 16:38
// * @Version 1.0.0.0
// **/
//@Service
//public class DownStationInfoServiceImpl implements DownStationInfoService {
//
//    @Autowired
//    private ProtocolAnalysis protocolAnalysis;
//
//    @Autowired(required = false)
//    private CardInfoMapper cardInfoMapper;
//
//    @Autowired(required = false)
//    private DownStationInfoMapper downStationInfoMapper;
//
//    @Autowired(required = false)
//    private StationInfoMapper stationInfoMapper;
//    @Autowired(required = false)
//    private CardReaderMapper cardReaderMapper;
//    //创建日志对象 Logger
//    static final Logger logger = LogManager.getLogger(DownStationInfoServiceImpl.class);
//
//    /**
//     * 分站电源管理
//     *
//     * @param stationId   分站ID
//     * @param powerAction 电源动作
//     */
//    @Override
//    public Map<String, Object> powerInfoManager(String stationId, String powerAction) {
//        try {
//            Callable myCallable = (Callable<String>) () -> {
//                String uniqueCode = NumberUtils.getRandomValue(4);
//                //包体数据
//                byte[] bodyBytes = protocolAnalysis.packPowerData(uniqueCode, powerAction);
//                //包头数据
//                byte[] headerBytes = protocolAnalysis.packPackageHeader("35", bodyBytes.length);
//                //数据包
//                byte[] packageBytes = TypeConvertUtils.concatBytes(headerBytes, bodyBytes);
//                //生成电源管理下行帧
//                byte[] downFrameBytes = protocolAnalysis.createDownFrame(stationId, packageBytes);
//                //过滤数据
//                List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                        .filter(a -> stationId.equals(a.get("StationCode").toString())).collect(Collectors.toList());
//                //分站名称
//                String stationName = "";
//                //下发数据
//                Socket socket = null;
//                if (filterStation.size() > 0) {
//                    socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//                    stationName = filterStation.get(0).get("StationName").toString();
//                }
//                String sendResult = MainObject.tcpServer.sendData(socket, downFrameBytes);
//                if (true == sendResult.equals("0")) {
//                    return "分站已离线，操作未下发";
//                }
//                MainObject.POWER_MANAGER_SEND_RECEIVER_MAP.put(uniqueCode, null);
//
//                //===========================数据库记录分站电源管理===================================
//                HashMap<String, Object> downStationMap = new HashMap<>();
//                String uniqueId = StringUtils.getUUID32();
//                downStationMap.put("ID", uniqueId);
//                if ("0".equals(powerAction)) {//放电
//                    downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.BatteryDischarge.getIndex());
//                    //downStationMap.put("ContentDetail", stationId + "号分站电池放电");
//                    downStationMap.put("ContentDetail", stationName + "电池放电");
//                } else if ("1".equals(powerAction)) {//充电
//                    downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.BatteryCharge.getIndex());
//                    //downStationMap.put("ContentDetail", stationId + "号分站电池充电");
//                    downStationMap.put("ContentDetail", stationName + "电池充电");
//                }
//                downStationMap.put("CreateTime", new Date());
//                downStationInfoMapper.insertDownStationInfo(downStationMap);
//                //====================================================================================
//
//                //时间计时器
//                int timeNum = 0;
//
//                while (true) {
//                    Thread.sleep(1000);
//                    //读取分站电源管理包
//                    UpPowerManagerPackage paramPackage = MainObject.POWER_MANAGER_SEND_RECEIVER_MAP.get(uniqueCode);
//
//                    //如果小于2秒且状态为成功
//                    if (timeNum < 10
//                            && paramPackage != null) {
//                        //===========================数据库记录分站电源管理===================================
//                        HashMap<String, Object> successMap = new HashMap<>();
//                        successMap.put("ID", uniqueId);
//                        successMap.put("ReceiveResult", paramPackage.getState());
//                        successMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(successMap);
//                        //====================================================================================
//                        //移除该键
//                        MainObject.POWER_MANAGER_SEND_RECEIVER_MAP.remove(uniqueCode);
//                        return paramPackage.getState();
//                    }
//                    //如果大于2秒
//                    if (timeNum >= 10) {
//                        //===========================数据库记录分站电源管理===================================
//                        HashMap<String, Object> failureMap = new HashMap<>();
//                        failureMap.put("ID", uniqueId);
//                        failureMap.put("ReceiveResult", "操作超时");
//                        failureMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(failureMap);
//                        //====================================================================================
//                        //移除该键
//                        MainObject.POWER_MANAGER_SEND_RECEIVER_MAP.remove(uniqueCode);
//                        return "操作超时";
//                    }
//                    timeNum++;
//                }
//            };
//            //根据代码段实例创建一个未来任务
//            FutureTask<String> future = new FutureTask<String>(myCallable);
//            //运行任务
//            future.run();
//
//            Map<String, Object> resultMap = new HashMap<>();
//            resultMap.put("result", future.get());
//
//            return resultMap;
//        } catch (Exception ex) {
//            return null;
//        }
//    }
//
//    /**
//     * 分站高级电源管理
//     *
//     * @param stationId       分站ID
//     * @param powerDeviceCode 电源编号
//     * @param powerAction     电源动作
//     */
//    @Override
//    public Map<String, Object> powerInfoManagerPlus(String stationId, String powerDeviceCode, String powerAction) {
//        try {
//            Callable myCallable = (Callable<String>) () -> {
//                String uniqueCode = NumberUtils.getRandomValue(4);
//                //包体数据
//                byte[] bodyBytes = protocolAnalysis.packPowerDataPlus(uniqueCode, powerDeviceCode, powerAction);
//                //包头数据
//                byte[] headerBytes = protocolAnalysis.packPackageHeader("38", bodyBytes.length);
//                //数据包
//                byte[] packageBytes = TypeConvertUtils.concatBytes(headerBytes, bodyBytes);
//                //生成电源管理下行帧
//                byte[] downFrameBytes = protocolAnalysis.createDownFrame(stationId, packageBytes);
//                //过滤数据
//                List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                        .filter(a -> stationId.equals(a.get("StationCode").toString())).collect(Collectors.toList());
//                //分站名称
//                String stationName = "";
//                //下发数据
//                Socket socket = null;
//                if (filterStation.size() > 0) {
//                    socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//                    stationName = filterStation.get(0).get("StationName").toString();
//                }
//                String sendResult = MainObject.tcpServer.sendData(socket, downFrameBytes);
//                if (true == sendResult.equals("0")) {
//                    return "分站已离线，操作未下发";
//                }
//                MainObject.POWER_MANAGER_PLUS_SEND_RECEIVER_MAP.put(uniqueCode, null);
//
//                //===========================数据库记录分站电源管理===================================
//                HashMap<String, Object> downStationMap = new HashMap<>();
//                String uniqueId = StringUtils.getUUID32();
//                downStationMap.put("ID", uniqueId);
//                if ("0".equals(powerAction)) {//放电
//                    downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.BatteryDischarge.getIndex());
//                    downStationMap.put("ContentDetail", stationName + "分站下，" + powerDeviceCode + "电池放电");
//                } else if ("1".equals(powerAction)) {//充电
//                    downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.BatteryCharge.getIndex());
//                    downStationMap.put("ContentDetail", stationName + "分站下，" + powerDeviceCode + "电池充电");
//                }
//                downStationMap.put("CreateTime", new Date());
//                downStationInfoMapper.insertDownStationInfo(downStationMap);
//                //====================================================================================
//
//                //时间计时器
//                int timeNum = 0;
//
//                while (true) {
//                    Thread.sleep(1000);
//                    //读取分站电源管理包
//                    UpPowerManagerPlusPackage paramPackage = MainObject.POWER_MANAGER_PLUS_SEND_RECEIVER_MAP.get(uniqueCode);
//
//                    //如果小于2秒且状态为成功
//                    if (timeNum < 10
//                            && paramPackage != null) {
//                        //===========================数据库记录分站电源管理===================================
//                        HashMap<String, Object> successMap = new HashMap<>();
//                        successMap.put("ID", uniqueId);
//                        successMap.put("ReceiveResult", paramPackage.getExecuteResult());
//                        successMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(successMap);
//                        //====================================================================================
//                        //移除该键
//                        MainObject.POWER_MANAGER_PLUS_SEND_RECEIVER_MAP.remove(uniqueCode);
//                        return paramPackage.getExecuteResult();
//                    }
//                    //如果大于2秒
//                    if (timeNum >= 10) {
//                        //===========================数据库记录分站电源管理===================================
//                        HashMap<String, Object> failureMap = new HashMap<>();
//                        failureMap.put("ID", uniqueId);
//                        failureMap.put("ReceiveResult", "操作超时");
//                        failureMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(failureMap);
//                        //====================================================================================
//                        //移除该键
//                        MainObject.POWER_MANAGER_PLUS_SEND_RECEIVER_MAP.remove(uniqueCode);
//                        return "操作超时";
//                    }
//                    timeNum++;
//                }
//            };
//            //根据代码段实例创建一个未来任务
//            FutureTask<String> future = new FutureTask<String>(myCallable);
//            //运行任务
//            future.run();
//
//            Map<String, Object> resultMap = new HashMap<>();
//            resultMap.put("result", future.get());
//
//            return resultMap;
//        } catch (Exception ex) {
//            return null;
//        }
//    }
//
//    /**
//     * 新告警信息下发
//     *
//     * @param stationId    分站ID
//     * @param cardDeviceId 标识卡ID
//     * @param cardReaderId 读卡器ID
//     * @param alarmType    告警类型 0:单卡告警   1:广播告警
//     * @param alarmState   告警动作 0：取消告警 1：发送告警
//     * @return
//     */
//    @Override
//    public Map<String, Object> newAlarmInfoManager(String stationId,
//                                                   String cardDeviceId,
//                                                   String cardReaderId,
//                                                   String alarmType,
//                                                   String alarmState,
//                                                   String isInSideMassage) {
//        try {
//            Callable myCallable = (Callable<String>) () -> {
//                String cardDeviceIdTemp = cardDeviceId;
//
//                //如果为1则为广播告警
//                if (alarmType.equals("1")) {
//                    cardDeviceIdTemp = "FFFFFFFF";
//                }
//                String uniqueCode = NumberUtils.getRandomValue(4);
//                //包体数据
//                byte[] bodyBytes = protocolAnalysis.packNewAlarm(uniqueCode, cardDeviceIdTemp, cardReaderId, alarmState);
//                //包头数据
//                byte[] headerBytes = protocolAnalysis.packPackageHeader("11", bodyBytes.length);
//                //数据包
//                byte[] packageBytes = TypeConvertUtils.concatBytes(headerBytes, bodyBytes);
//                //生成新告警管理下行帧
//                byte[] downFrameBytes = protocolAnalysis.createDownFrame(stationId, packageBytes);
//                //过滤数据
//                List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                        .filter(a -> stationId.equals(a.get("StationCode").toString())).collect(Collectors.toList());
//                //下发数据
//                Socket socket = null;
//                if (filterStation.size() > 0) {
//                    socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//                }
//                MainObject.tcpServer.sendData(socket, downFrameBytes);
//
//                MainObject.NEW_ALARM_SEND_RECEIVER__MAP.put(uniqueCode, null);
//
//                //===========================数据库记录新告警信息下发===================================
//                HashMap<String, Object> downStationMap = new HashMap<>();
//                String uniqueId = StringUtils.getUUID32();
//                downStationMap.put("ID", uniqueId);
//                if (isInSideMassage.equals("1")) {
//                    if ("1".equals(alarmState)) {//告警开始
//                        downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.ShakeStart.getIndex());
//                    } else if ("0".equals(alarmState)) {//取消告警
//                        downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.ShakeEnd.getIndex());
//                    }
//                } else {
//                    if ("1".equals(alarmState)) {//联动开始
//                        downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.LinkShakeStart.getIndex());
//                    } else if ("0".equals(alarmState)) {//联动取消
//                        downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.LinkShakeEnd.getIndex());
//                    }
//                }
//
//                if ("1".equals(alarmType)) {//告警群发
//                    String readerName = "";
//                    //过滤数据
//                    List<HashMap<String, Object>> filterCardReader = MainObject.CARD_READER_INFO_LIST.stream()
//                            .filter(a -> cardReaderId.equals(a.get("ReaderCode").toString())).collect(Collectors.toList());
//                    if (filterCardReader.size() > 0) {
//                        readerName = filterCardReader.get(0).get("ReaderName").toString();
//                    }
//
//                    if ("1".equals(alarmState)) {//告警开始
//                        //downStationMap.put("ContentDetail", cardReaderId + "号读卡器下所有卡发送告警");
//                        downStationMap.put("ContentDetail", readerName + "下所有卡发送告警");
//                    } else if ("0".equals(alarmState)) {//取消告警
//                        //downStationMap.put("ContentDetail", cardReaderId + "号读卡器下所有卡取消告警");
//                        downStationMap.put("ContentDetail", readerName + "下所有卡取消告警");
//                    }
//                } else {
//                    String personName = "";
//                    List<Map<String, Object>> filterPersonCardList = MainObject.PERSON_CARD_INFO_LIST.stream()
//                            .filter(a -> a.get("DeviceID").equals(cardDeviceId)).collect(Collectors.toList());
//                    if (filterPersonCardList.size() > 0) {
//                        personName = filterPersonCardList.get(0).get("PersonName").toString();
//                    }
//                    if ("1".equals(alarmState)) {//告警开始
//                        //downStationMap.put("ContentDetail", cardDeviceId + "号卡发送告警");
//                        downStationMap.put("ContentDetail", personName + "的卡发送告警");
//                    } else if ("0".equals(alarmState)) {//取消告警
//                        //downStationMap.put("ContentDetail", cardDeviceId + "号卡取消告警");
//                        downStationMap.put("ContentDetail", personName + "的卡取消告警");
//                    }
//                }
//                downStationMap.put("CreateTime", new Date());
//                downStationInfoMapper.insertDownStationInfo(downStationMap);
//                //====================================================================================
//
//
//                //时间计时器
//                int timeNum = 0;
//
//                while (true) {
//                    Thread.sleep(1000);
//                    //读取写参数包
//                    UpNewAlarmPackage paramPackage = MainObject.NEW_ALARM_SEND_RECEIVER__MAP.get(uniqueCode);
//
//                    //如果小于2秒且状态为成功
//                    if (timeNum < 10
//                            && paramPackage != null) {
//                        //===========================数据库记录新告警信息下发==================================
//                        HashMap<String, Object> successMap = new HashMap<>();
//                        successMap.put("ID", uniqueId);
//                        successMap.put("ReceiveResult", paramPackage.getAnswerState());
//                        successMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(successMap);
//                        //====================================================================================
//                        //移除该键
//                        MainObject.NEW_ALARM_SEND_RECEIVER__MAP.remove(uniqueCode);
//                        return paramPackage.getAnswerState();
//                    }
//                    //如果大于10秒
//                    if (timeNum >= 10) {
//                        //===========================数据库记录时钟同步信息===================================
//                        HashMap<String, Object> failureMap = new HashMap<>();
//                        failureMap.put("ID", uniqueId);
//                        failureMap.put("ReceiveResult", "操作超时或失败");
//                        failureMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(failureMap);
//                        //====================================================================================
//                        //移除该键
//                        MainObject.NEW_ALARM_SEND_RECEIVER__MAP.remove(uniqueCode);
//                        return "操作超时或失败";
//                    }
//                    timeNum++;
//                }
//            };
//            //根据代码段实例创建一个未来任务
//            FutureTask<String> future = new FutureTask<String>(myCallable);
//            //运行任务
//            future.run();
//
//            Map<String, Object> resultMap = new HashMap<>();
//            resultMap.put("result", future.get());
//
//            return resultMap;
//        } catch (Exception ex) {
//            return null;
//        }
//    }
//
//
//    /**
//     * 告警信息下发
//     *
//     * @param stationId    分站ID
//     * @param cardDeviceId 标识卡ID
//     * @param cardReaderId 读卡器ID
//     * @param alarmType    告警类型 0:单卡告警   1:广播告警
//     */
//    public void alarmInfoManager(String stationId, String cardDeviceId, String cardReaderId, String alarmType, String alarmState) {
//        try {
//            //如果为1则为广播告警
//            if (alarmType.equals("1")) {
//                cardDeviceId = "FFFFFFFF";
//            }
//            String uniqueCode = NumberUtils.getRandomValue(4);
//            //包体数据
//            byte[] bodyBytes = null; //protocolAnalysis.packNewAlarm(uniqueCode,cardDeviceId,cardReaderId,alarmState);
//            //包头数据
//            byte[] headerBytes = protocolAnalysis.packPackageHeader("0C", bodyBytes.length);
//            //数据包
//            byte[] packageBytes = TypeConvertUtils.concatBytes(headerBytes, bodyBytes);
//            //生成告警管理下行帧
//            byte[] downFrameBytes = protocolAnalysis.createDownFrame(stationId, packageBytes);
//            //过滤数据
//            List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                    .filter(a -> stationId.equals(a.get("StationCode").toString())).collect(Collectors.toList());
//            //下发数据
//            Socket socket = null;
//            if (filterStation.size() > 0) {
//                socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//            }
//            MainObject.tcpServer.sendData(socket, downFrameBytes);
//
//
//        } catch (Exception ex) {
//
//        }
//    }
//
//    /**
//     * 读卡器读参数包下发
//     *
//     * @param stationCode  分站编号
//     * @param cardReaderId 读卡器ID
//     * @param paramNum     参数号
//     * @return
//     */
//    @Override
//    public Map<String, Object> cardReaderParamRead(String stationCode,
//                                                   String cardReaderId,
//                                                   String paramNum) {
//        try {
//            Callable myCallable = (Callable<Object>) () -> {
//                String uniqueCode = NumberUtils.getRandomValue(4);
//                //包体数据
//                byte[] bodyBytes = protocolAnalysis.packCardReaderReadParam(uniqueCode, cardReaderId, paramNum);
//                //包头数据
//                byte[] headerBytes = protocolAnalysis.packPackageHeader("12", bodyBytes.length);
//                //数据包
//                byte[] packageBytes = TypeConvertUtils.concatBytes(headerBytes, bodyBytes);
//                //生成读卡器读参数下行帧
//                byte[] downFrameBytes = protocolAnalysis.createDownFrame(stationCode, packageBytes);
//                //根据分站编号筛选
//                List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                        .filter(a -> stationCode.equals(a.get("StationCode").toString())).collect(Collectors.toList());
//                //下发数据
//                Socket socket = null;
//                if (filterStation.size() > 0) {
//                    socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//                }
//                MainObject.tcpServer.sendData(socket, downFrameBytes);
//                MainObject.CARD_READER_READ_PARAM_SEND_RECEIVER_MAP.put(uniqueCode, null);
//
//                String readerName = "";
//                //过滤数据
//                List<HashMap<String, Object>> filterCardReader = MainObject.CARD_READER_INFO_LIST.stream()
//                        .filter(a -> cardReaderId.equals(a.get("ReaderCode").toString())).collect(Collectors.toList());
//                if (filterCardReader.size() > 0) {
//                    readerName = filterCardReader.get(0).get("ReaderName").toString();
//                }
//
//                //===================================================================================
//                HashMap<String, Object> downStationMap = new HashMap<>();
//                String uniqueId = StringUtils.getUUID32();
//                downStationMap.put("ID", uniqueId);
//                downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.ReaderConfig.getIndex());
//                downStationMap.put("ContentDetail", readerName + "参数读取信息");
//                downStationMap.put("CreateTime", new Date());
//                downStationInfoMapper.insertDownStationInfo(downStationMap);
//                //====================================================================================
//
//                //时间计数器
//                int timeNum = 0;
//                //循环读取返回值
//                while (true) {
//                    Thread.sleep(1000);
//                    //读取读参数包
//                    UpCardReaderReadPackage paramPackage = MainObject.CARD_READER_READ_PARAM_SEND_RECEIVER_MAP.get(uniqueCode);
//
//                    //如果小于2秒且状态为成功
//                    if (timeNum < 20
//                            && paramPackage != null) {
//
//                        //===========================数据库记录信息===================================
//                        HashMap<String, Object> successMap = new HashMap<>();
//                        //判断操作是否成功
//                        if (!paramPackage.getResult().equals("操作成功")) {
//                            successMap.put("ResultContent", null);
//                        } else {
//                            //正则去零
//                            successMap.put("ResultContent", paramPackage.getParamValue().replaceAll("^(0+)", ""));//返回内容
//                        }
//                        successMap.put("ReceiveResult", paramPackage.getResult());
//                        successMap.put("ID", uniqueId);
//                        successMap.put("ReceiveTime", new Date());
//
//                        downStationInfoMapper.updateDownStationInfo(successMap);
//                        //移除该键
//                        MainObject.CARD_READER_READ_PARAM_SEND_RECEIVER_MAP.remove(uniqueCode);
//                        return successMap;
//                    }
//                    //如果大于2秒
//                    if (timeNum >= 20) {
//
//                        //===========================数据库记录时钟同步信息===================================
//                        HashMap<String, Object> failureMap = new HashMap<>();
//                        failureMap.put("ID", uniqueId);
//                        failureMap.put("ReceiveResult", "操作超时或失败");
//                        failureMap.put("ResultContent", null);//返回内容
//                        failureMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(failureMap);
//                        //====================================================================================
//
//                        //移除该键
//                        MainObject.CARD_READER_READ_PARAM_SEND_RECEIVER_MAP.remove(uniqueCode);
//                        return failureMap;
//                    }
//                    timeNum++;
//                }
//            };
//            //根据代码段实例创建一个未来任务
//            FutureTask<Object> future = new FutureTask<Object>(myCallable);
//            //运行任务
//            future.run();
//            HashMap<String, Object> returnMap = (HashMap<String, Object>) future.get();
//            Map<String, Object> resultMap = new HashMap<>();
//            resultMap.put("ReceiveResult", returnMap.get("ReceiveResult"));
//            resultMap.put("ResultContent", returnMap.get("ResultContent"));
//            return resultMap;
//        } catch (Exception ex) {
//            ex.printStackTrace();
//            return null;
//        }
//
//    }
//
//
//    /**
//     * 读卡器写参数包下发
//     *
//     * @param stationCode  分站编号
//     * @param cardReaderId 读卡器ID
//     * @param paramNum     参数号
//     * @param paramValue   参数值
//     * @return
//     */
//    @Override
//    public Map<String, Object> cardReaderParamWrite(String stationCode,
//                                                    String cardReaderId,
//                                                    String paramNum,
//                                                    String paramValue) {
//        try {
//            Callable myCallable = (Callable<Object>) () -> {
//                String uniqueCode = NumberUtils.getRandomValue(4);
//                //包体数据
//                byte[] bodyBytes = protocolAnalysis.packCardWriteReadParam(uniqueCode, cardReaderId, paramNum, paramValue);
//                //包头数据
//                byte[] headerBytes = protocolAnalysis.packPackageHeader("13", bodyBytes.length);
//                //数据包
//                byte[] packageBytes = TypeConvertUtils.concatBytes(headerBytes, bodyBytes);
//                //生成读卡器读参数下行帧
//                byte[] downFrameBytes = protocolAnalysis.createDownFrame(stationCode, packageBytes);
//                //根据分站编号筛选
//                List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                        .filter(a -> stationCode.equals(a.get("StationCode").toString())).collect(Collectors.toList());
//                //下发数据
//                Socket socket = null;
//                if (filterStation.size() > 0) {
//                    socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//                }
//                MainObject.tcpServer.sendData(socket, downFrameBytes);
//                MainObject.CARD_READER_WRITE_PARAM_SEND_RECEIVER_MAP.put(uniqueCode, null);
//
//                String readerName = "";
//                //过滤数据
//                List<HashMap<String, Object>> filterCardReader = MainObject.CARD_READER_INFO_LIST.stream()
//                        .filter(a -> cardReaderId.equals(a.get("ReaderCode").toString())).collect(Collectors.toList());
//                if (filterCardReader.size() > 0) {
//                    readerName = filterCardReader.get(0).get("ReaderName").toString();
//                }
//
//                //===================================================================================
//                HashMap<String, Object> downStationMap = new HashMap<>();
//                String uniqueId = StringUtils.getUUID32();
//                downStationMap.put("ID", uniqueId);
//                downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.ReaderConfig.getIndex());
//                downStationMap.put("ContentDetail", readerName + "写参数信息" + paramNum + ":" + paramValue);
//                downStationMap.put("CreateTime", new Date());
//                downStationInfoMapper.insertDownStationInfo(downStationMap);
//                //====================================================================================
//
//                //时间计数器
//                int timeNum = 0;
//                //循环读取返回值
//                while (true) {
//                    Thread.sleep(1000);
//                    //读取读参数包
//
//                    UpCardReaderWritePackage paramPackage = MainObject.CARD_READER_WRITE_PARAM_SEND_RECEIVER_MAP.get(uniqueCode);
//
//                    //如果小于2秒且状态为成功
//                    if (timeNum < 20
//                            && paramPackage != null) {
//
//                        //===========================数据库记录信息===================================
//                        HashMap<String, Object> successMap = new HashMap<>();
//                        successMap.put("ResultContent", null);
//                        successMap.put("ReceiveResult", paramPackage.getResult());
//                        successMap.put("ID", uniqueId);
//                        successMap.put("ReceiveTime", new Date());
//
//                        downStationInfoMapper.updateDownStationInfo(successMap);
//                        //移除该键
//                        MainObject.CARD_READER_WRITE_PARAM_SEND_RECEIVER_MAP.remove(uniqueCode);
//                        return successMap;
//                    }
//                    //如果大于2秒
//                    if (timeNum >= 20) {
//
//                        //===========================数据库记录时钟同步信息===================================
//                        HashMap<String, Object> failureMap = new HashMap<>();
//                        failureMap.put("ID", uniqueId);
//                        failureMap.put("ReceiveResult", "操作超时或失败");
//                        failureMap.put("ResultContent", null);//返回内容
//                        failureMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(failureMap);
//                        //====================================================================================
//
//                        //移除该键
//                        MainObject.CARD_READER_WRITE_PARAM_SEND_RECEIVER_MAP.remove(uniqueCode);
//                        return failureMap;
//                    }
//                    timeNum++;
//                }
//            };
//            //根据代码段实例创建一个未来任务
//            FutureTask<Object> future = new FutureTask<Object>(myCallable);
//            //运行任务
//            future.run();
//            HashMap<String, Object> returnMap = (HashMap<String, Object>) future.get();
//            Map<String, Object> resultMap = new HashMap<>();
//            resultMap.put("ReceiveResult", returnMap.get("ReceiveResult"));
//            resultMap.put("ResultContent", returnMap.get("ResultContent"));
//            return resultMap;
//        } catch (Exception ex) {
//            ex.printStackTrace();
//            return null;
//        }
//
//    }
//
//    /**
//     * 发送短信告警
//     *
//     * @param stationId      分站ID
//     * @param cardDeviceId   卡设备ID
//     * @param cardReaderId   读卡器ID
//     * @param messageType    下发短信类型 0：单卡告警   1：广播告警
//     * @param messageContent 短信内容
//     * @return
//     */
//    @Override
//    public Map<String, Object> sendMessage(String stationId,
//                                           String cardDeviceId,
//                                           String cardReaderId,
//                                           String messageType,
//                                           String messageContent) {
//        try {
//            Callable myCallable = (Callable<String>) () -> {
//                String cardDeviceIdTemp = cardDeviceId;
//                //如果为1则为广播告警
//                if (messageType.equals("1")) {
//                    cardDeviceIdTemp = "FFFFFFFF";
//                }
//                String uniqueCode = NumberUtils.getRandomValue(4);
//
//                SimpleDateFormat dateFormat = new SimpleDateFormat("M月d日 HH:mm");
//                Date date = new Date();
//                String createTime = dateFormat.format(date);
//                byte[] bodyBytes;
//                if (messageContent.contains("@#配置") == true || messageContent.contains("@#清除") == true || messageContent.contains("@#清储") == true) {
//                    //包体数据
//                    bodyBytes = protocolAnalysis.packMessage(uniqueCode, cardDeviceIdTemp, cardReaderId, messageContent);
//                } else {
//                    //包体数据
//                    bodyBytes = protocolAnalysis.packMessage(uniqueCode, cardDeviceIdTemp, cardReaderId, createTime + "    " + messageContent);
//                }
//                //包头数据
//                byte[] headerBytes = protocolAnalysis.packPackageHeader("0F", bodyBytes.length);
//                //数据包
//                byte[] packageBytes = TypeConvertUtils.concatBytes(headerBytes, bodyBytes);
//                //生成短信下行帧
//                byte[] downFrameBytes = protocolAnalysis.createDownFrame(stationId, packageBytes);
//                //根据分站编号筛选
//                List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                        .filter(a -> stationId.equals(a.get("StationCode").toString())).collect(Collectors.toList());
//                //下发数据
//                Socket socket = null;
//                if (filterStation.size() > 0) {
//                    socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//                }
//                MainObject.tcpServer.sendData(socket, downFrameBytes);
//
//                MainObject.MESSAGE_SEND_RECEIVER__MAP.put(uniqueCode, null);
//
//                String readerName = "";
//                //过滤数据
//                List<HashMap<String, Object>> filterCardReader = MainObject.CARD_READER_INFO_LIST.stream()
//                        .filter(a -> cardReaderId.equals(a.get("ReaderCode").toString())).collect(Collectors.toList());
//                if (filterCardReader.size() > 0) {
//                    readerName = filterCardReader.get(0).get("ReaderName").toString();
//                }
//
//                //===========================数据库记录发送短信告警====================================
//                HashMap<String, Object> downStationMap = new HashMap<>();
//                String uniqueId = StringUtils.getUUID32();
//                downStationMap.put("ID", uniqueId);
//
//                if ("1".equals(messageType)) {//告警群发
//                    downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.DownMessage.getIndex());
//                    downStationMap.put("ContentDetail", readerName + "下所有卡发送短信为：" + messageContent);
//                } else {
//                    String personName = "";
//                    List<Map<String, Object>> filterPersonCardList = MainObject.PERSON_CARD_INFO_LIST.stream()
//                            .filter(a -> a.get("DeviceID").equals(cardDeviceId)).collect(Collectors.toList());
//                    if (filterPersonCardList.size() > 0) {
//                        personName = filterPersonCardList.get(0).get("PersonName").toString();
//                    }
//                    if (messageContent.contains("@#配置") == true) {
//                        downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.CardNumConfig.getIndex());
//                        downStationMap.put("ContentDetail", cardDeviceId + "号卡发送配置为：" + messageContent.split(":")[1].split(";")[1]);
//                    } else if (messageContent.contains("@#清除") == true) {
//                        downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.ClearCardContent.getIndex());
//                        downStationMap.put("ContentDetail", personName + "的卡配置清除");
//                    } else if (messageContent.contains("@#清储") == true) {
//                        downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.ClearCardContent.getIndex());
//                        downStationMap.put("ContentDetail", personName + "的卡短信清除");
//                    } else {
//                        downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.DownMessage.getIndex());
//                        downStationMap.put("ContentDetail", personName + "的卡发送短信为：" + messageContent);
//                    }
//
//                }
//                downStationMap.put("CreateTime", new Date());
//                downStationInfoMapper.insertDownStationInfo(downStationMap);
//                //====================================================================================
//
//                //时间计时器
//                int timeNum = 0;
//
//                while (true) {
//                    Thread.sleep(1000);
//                    //读取写参数包
//                    UpMessagePackage paramPackage = MainObject.MESSAGE_SEND_RECEIVER__MAP.get(uniqueCode);
//
//                    //如果小于2秒且状态为成功
//                    if (timeNum < 10
//                            && paramPackage != null) {
//                        //===========================数据库记录发送短信告警====================================
//                        HashMap<String, Object> successMap = new HashMap<>();
//                        successMap.put("ID", uniqueId);
//                        successMap.put("ReceiveResult", paramPackage.getAnswerState());
//                        successMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(successMap);
//                        //====================================================================================
//                        //移除该键
//                        MainObject.MESSAGE_SEND_RECEIVER__MAP.remove(uniqueCode);
//                        return paramPackage.getAnswerState();
//                    }
//                    //如果大于2秒
//                    if (timeNum >= 10) {
//                        //===========================数据库记录发送短信告警====================================
//                        HashMap<String, Object> failureMap = new HashMap<>();
//                        failureMap.put("ID", uniqueId);
//                        failureMap.put("ReceiveResult", "操作超时或失败");
//                        failureMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(failureMap);
//                        //====================================================================================
//                        //移除该键
//                        MainObject.MESSAGE_SEND_RECEIVER__MAP.remove(uniqueCode);
//                        return "操作超时或失败";
//                    }
//                    timeNum++;
//                }
//            };
//            //根据代码段实例创建一个未来任务
//            FutureTask<String> future = new FutureTask<String>(myCallable);
//            //运行任务
//            future.run();
//
//            Map<String, Object> resultMap = new HashMap<>();
//            resultMap.put("result", future.get());
//
//            return resultMap;
//        } catch (Exception ex) {
//            return null;
//        }
//    }
//
//    /**
//     * 发送标识卡信息
//     *
//     * @param stationId
//     */
//    @Override
//    public Map<String, Object> sendCardInfo(String stationId) {
//        try {
//            //查询标识卡列表信息
//            List<Map<String, Object>> listCardInfo = cardInfoMapper.listGrantedCard(null);
//            //人员卡集合对8取余数（一个卡包信息里最多包含8张卡）
//            int remainder = listCardInfo.size() % 8;
//            //人员卡集合对8取整（一个卡包信息里最多包含8张卡）
//            int divideNum = listCardInfo.size() / 8 + (remainder == 0 ? 0 : 1);
//            //包序
//            //int packageSort = 0;
//            String versionCode = NumberUtils.getRandomValue(4);
//            //默认执行结果
//            String executeResult = "操作失败";
//            //人员卡下发进度
//            MainObject.PROGRESS_OF_ISSUING_PERSON_CARD_INFORMATION.put("status", true);
//            MainObject.PROGRESS_OF_ISSUING_PERSON_CARD_INFORMATION.put("process", 0);
//
//
//            //===========================数据库记录标识卡配置信息===================================
//            HashMap<String, Object> downStationMap = new HashMap<>();
//            String uniqueId = StringUtils.getUUID32();
//            downStationMap.put("ID", uniqueId);
//            downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.CardConfig.getIndex());
//            downStationMap.put("ContentDetail", stationId + "号分站,发送标识卡配置");
//            downStationMap.put("CreateTime", new Date());
//            downStationInfoMapper.insertDownStationInfo(downStationMap);
//            //====================================================================================
//
//
//            //循环截取标识卡信息列表
//            for (int i = 0; i < divideNum; i++) {
//                //截取每一包数据
//                List<Map<String, Object>> listCard = null;
//                if (remainder == 0 || (remainder != 0 && i != (divideNum - 1))) {
//                    listCard = listCardInfo.subList(i * 8, i * 8 + 8);
//                } else {
//                    listCard = listCardInfo.subList(i * 8, listCardInfo.size());
//                }
//                final List<Map<String, Object>> listCardTemp = listCard;
//
//                //包序
//                final int packageSort = i + 1;
//
//                Callable myCallable = (Callable<String>) () -> {
//
//                    String uniqueCode = NumberUtils.getRandomValue(4);
//                    //包体数据
//                    byte[] bodyBytes = protocolAnalysis.packCardInfoPackage(uniqueCode, packageSort, versionCode, listCardTemp);
//                    //包头数据
//                    byte[] headerBytes = protocolAnalysis.packPackageHeader("22", bodyBytes.length);
//                    //数据包
//                    byte[] packageBytes = TypeConvertUtils.concatBytes(headerBytes, bodyBytes);
//                    //生成标识卡下行帧
//                    byte[] downFrameBytes = protocolAnalysis.createDownFrame(stationId, packageBytes);
//
//                    List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                            .filter(a -> stationId.equals(a.get("StationCode").toString())).collect(Collectors.toList());
//                    //下发数据
//                    Socket socket = null;
//                    if (filterStation.size() > 0) {
//                        socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//                    }
//                    Thread.sleep(500);
//
//                    MainObject.tcpServer.sendData(socket, downFrameBytes);
//
//                    MainObject.CARD_SEND_RECEIVE_MAP.put(uniqueCode, null);
//
//
//                    //时间计时器
//                    int timeNum = 0;
//
//                    while (true) {
//                        Thread.sleep(1000);
//                        //读取卡上行包
//                        UpCardInfoPackage paramPackage = MainObject.CARD_SEND_RECEIVE_MAP.get(uniqueCode);
//
//                        //如果小于2秒且状态为成功
//                        if (timeNum < 10
//                                && paramPackage != null) {
//                            //移除该键
//                            MainObject.CARD_SEND_RECEIVE_MAP.remove(uniqueCode);
//                            return paramPackage.getExecuteResult();
//                        }
//                        //如果大于2秒
//                        if (timeNum >= 10) {
//                            //移除该键
//                            MainObject.CARD_SEND_RECEIVE_MAP.remove(uniqueCode);
//                            return "操作超时或失败";
//                        }
//                        timeNum++;
//                    }
//                };
//                //根据代码段实例创建一个未来任务
//                FutureTask<String> future = new FutureTask<String>(myCallable);
//                //运行任务
//                future.run();
//                //获取返回结果
//                executeResult = future.get();
//                Map<String, Object> resultMap = new HashMap<>();
//                //如果单次出现失败或者超时，则直接返回
//                if ("操作超时或失败".equals(executeResult)) {
//
//                    resultMap.put("result", future.get());
//
//                    MainObject.PROGRESS_OF_ISSUING_PERSON_CARD_INFORMATION.put("status", false);
//                    MainObject.PROGRESS_OF_ISSUING_PERSON_CARD_INFORMATION.put("process", 0.0);
//                    logger.info(stationId + "号分站，标识卡下发超时或失败");
//                    break;
//                } else if ("操作成功".equals(executeResult)) {
//                    //进度计算
//                    String speedOfProgress = null;
//                    if (remainder == 0 || (remainder != 0 && i != (divideNum - 1))) {
//                        speedOfProgress = new DecimalFormat("#.0").format((i + 1) * 8.0 / listCardInfo.size() * 100);
//                    } else {
//                        speedOfProgress = "100.0";
//                    }
//                    //放置进度
//                    MainObject.PROGRESS_OF_ISSUING_PERSON_CARD_INFORMATION.put("status", true);
//                    MainObject.PROGRESS_OF_ISSUING_PERSON_CARD_INFORMATION.put("process", Double.valueOf(speedOfProgress));
//                    logger.info(stationId + "号分站，标识卡下发进度" + Double.valueOf(speedOfProgress));
//                } else {
//                    resultMap.put("result", future.get());
//                    MainObject.PROGRESS_OF_ISSUING_PERSON_CARD_INFORMATION.put("status", false);
//                    MainObject.PROGRESS_OF_ISSUING_PERSON_CARD_INFORMATION.put("process", 0.0);
//                    logger.info(stationId + "号分站，标识卡下发返回其他结果");
//                    break;
//                }
//
//            }
//
//            //===========================数据库更新标识卡配置信息=================================
//            HashMap<String, Object> resultMap = new HashMap<>();
//            resultMap.put("ID", uniqueId);
//            resultMap.put("ReceiveResult", executeResult);
//            resultMap.put("ReceiveTime", new Date());
//            downStationInfoMapper.updateDownStationInfo(resultMap);
//            //====================================================================================
//            return resultMap;
//        } catch (Exception ex) {
//            //下发异常
//            MainObject.PROGRESS_OF_ISSUING_PERSON_CARD_INFORMATION.put("status", false);
//            MainObject.PROGRESS_OF_ISSUING_PERSON_CARD_INFORMATION.put("process", 0.0);
//
//            ex.printStackTrace();
//            return null;
//        }
//    }
//
//    /**
//     * 发送读卡器信息
//     *
//     * @param stationId
//     */
//    @Override
//    public Map<String, Object> sendCardReaderInfo(String stationId) {
//        try {
//            //默认执行结果
//            String executeResult = "操作失败";
//
//            //通过分站Code获取相应的分站信息
//            HashMap<String, Object> stationMap = new HashMap<>();
//            stationMap.put("StationCode", stationId);
//            List<HashMap<String, Object>> stationFilterList = stationInfoMapper.findStationInfo(stationMap);
//            if (stationFilterList.size() > 0) {
//
//                //读卡器信息下发进度开始
//                MainObject.PROGRESS_OF_ISSUING_READER_CARD_INFORMATION.put("status", true);
//                MainObject.PROGRESS_OF_ISSUING_READER_CARD_INFORMATION.put("process", 0);
//
//
//                HashMap<String, Object> readerStationInfo = stationFilterList.get(0);
//                //通过分站Id获取读卡器列表
//                HashMap<String, Object> cardReaderMap = new HashMap<>();
//                cardReaderMap.put("StationID", readerStationInfo.get("ID"));
//                List<Map<String, Object>> cardReaderInfoList = cardReaderMapper.listCardReaderByStationID(cardReaderMap);
//
//
//                String versionCode = NumberUtils.getRandomValue(4);
//                if (cardReaderInfoList == null) {
//                    return null;
//                }
//                for (int inclusionOrder = 0; inclusionOrder < cardReaderInfoList.size(); inclusionOrder++) {
//                    Map<String, Object> cardReaderInfo = cardReaderInfoList.get(inclusionOrder);
//                    String cardReaderId = cardReaderInfo.get("ReaderCode").toString();
//                    String cardReaderName = cardReaderInfo.get("ReaderName").toString();
//
//                    int finalInclusionOrder = inclusionOrder + 1;
//                    Callable myCallable = (Callable<String>) () -> {
//                        String uniqueCode = NumberUtils.getRandomValue(4);
//                        //包体数据
//                        byte[] bodyBytes = protocolAnalysis.packCardReaderPackage(uniqueCode, cardReaderId, cardReaderName, finalInclusionOrder, versionCode);
//                        //包头数据
//                        byte[] headerBytes = protocolAnalysis.packPackageHeader("23", bodyBytes.length);
//                        //数据包
//                        byte[] packageBytes = TypeConvertUtils.concatBytes(headerBytes, bodyBytes);
//                        //生成读卡器下行帧
//                        byte[] downFrameBytes = protocolAnalysis.createDownFrame(stationId, packageBytes);
//
//                        List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                                .filter(a -> stationId.equals(a.get("StationCode").toString())).collect(Collectors.toList());
//                        //下发数据
//                        Socket socket = null;
//                        if (filterStation.size() > 0) {
//                            socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//                        }
//                        MainObject.tcpServer.sendData(socket, downFrameBytes);
//                        MainObject.CARD_READER_SEND_RECEIVER_MAP.put(uniqueCode, null);
//                        //===========================数据库记录读卡器配置信息===================================
//                        HashMap<String, Object> downStationMap = new HashMap<>();
//                        String uniqueId = StringUtils.getUUID32();
//                        downStationMap.put("ID", uniqueId);
//                        downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.ReaderConfig.getIndex());
//                        downStationMap.put("ContentDetail", stationId + "号分站," + cardReaderId + "读卡器" + "发送配置");
//                        downStationMap.put("CreateTime", new Date());
//                        downStationInfoMapper.insertDownStationInfo(downStationMap);
//                        //====================================================================================
//
//                        //时间计数器
//                        int timeNum = 0;
//                        //循环读取返回值
//                        while (true) {
//                            Thread.sleep(1000);
//                            //读取写参数包
//                            UpCardReaderInfoPackage paramPackage = MainObject.CARD_READER_SEND_RECEIVER_MAP.get(uniqueCode);
//
//                            //如果小于2秒且状态为成功
//                            if (timeNum < 10
//                                    && paramPackage != null) {
//
//                                //===========================数据库记录读卡器配置信息==================================
//                                HashMap<String, Object> successMap = new HashMap<>();
//                                successMap.put("ID", uniqueId);
//                                successMap.put("ReceiveResult", paramPackage.getExecuteResult());
//                                successMap.put("ReceiveTime", new Date());
//                                downStationInfoMapper.updateDownStationInfo(successMap);
//                                //====================================================================================
//
//                                //移除该键
//                                MainObject.CARD_READER_SEND_RECEIVER_MAP.remove(uniqueCode);
//                                return paramPackage.getExecuteResult();
//                            }
//                            //如果大于2秒
//                            if (timeNum >= 10) {
//                                //===========================数据库记录读卡器配置信息==================================
//                                HashMap<String, Object> failMap = new HashMap<>();
//                                failMap.put("ID", uniqueId);
//                                failMap.put("ReceiveResult", "操作超时或失败");
//                                failMap.put("ReceiveTime", new Date());
//                                downStationInfoMapper.updateDownStationInfo(failMap);
//                                //====================================================================================
//
//                                //移除该键
//                                MainObject.CARD_READER_SEND_RECEIVER_MAP.remove(uniqueCode);
//                                return "操作超时或失败";
//                            }
//                            timeNum++;
//
//                        }
//                    };
//                    //根据代码段实例创建一个未来任务
//                    FutureTask<String> future = new FutureTask<String>(myCallable);
//                    //运行任务
//                    future.run();
//                    //获取返回结果
//                    executeResult = future.get();
//
//                    Map<String, Object> resultMap = new HashMap<>();
//                    //如果单次出现失败或者超时，则直接返回
//                    if ("操作成功".equals(executeResult)) {
//                        String speedOfProgress = new DecimalFormat("#.0").format((inclusionOrder + 1.0) / cardReaderInfoList.size() * 100);
//                        MainObject.PROGRESS_OF_ISSUING_READER_CARD_INFORMATION.put("status", true);
//                        MainObject.PROGRESS_OF_ISSUING_READER_CARD_INFORMATION.put("process", Double.valueOf(speedOfProgress));
//                    } else {
//                        resultMap.put("result", future.get());
//                        MainObject.PROGRESS_OF_ISSUING_READER_CARD_INFORMATION.put("status", false);
//                        MainObject.PROGRESS_OF_ISSUING_READER_CARD_INFORMATION.put("process", 0.0);
//                        return resultMap;
//                    }
//
//                }
//            } else {
//                executeResult = "本分站下没有读卡器";
//            }
//            Map<String, Object> resultMap = new HashMap<>();
//            resultMap.put("result", executeResult);
//            return resultMap;
//        } catch (Exception ex) {
//            MainObject.PROGRESS_OF_ISSUING_READER_CARD_INFORMATION.put("status", false);
//            MainObject.PROGRESS_OF_ISSUING_READER_CARD_INFORMATION.put("process", 0.0);
//            return null;
//        }
//    }
//
//    /**
//     * 发送分站时钟同步
//     *
//     * @param stationId 分站ID
//     */
//    @Override
//    public Map<String, Object> sendStationClock(String stationId) {
//        try {
//            Callable myCallable = (Callable<String>) () -> {
//                //=======================生成日期和时间===========================================
//                Calendar now = Calendar.getInstance();
//                String strYear = Integer.toString(now.get(Calendar.YEAR) - 2000);//年
//                String strMonth = String.format("%02d", (now.get(Calendar.MONTH) + 1));//月
//                String strDay = String.format("%02d", (now.get(Calendar.DAY_OF_MONTH)));//日
//                String strHour = String.format("%02d", (now.get(Calendar.HOUR_OF_DAY)));//时
//                String strMinute = String.format("%02d", (now.get(Calendar.MINUTE)));//分
//                String strSecond = String.format("%02d", (now.get(Calendar.SECOND)));//秒
//                String strMillis = "00";//毫秒
//                String dateData = strYear + strMonth + strDay + "00";//日期
//                String timeData = strHour + strMinute + strSecond + strMillis;//时间
//                //===============================================================================
//                //=========================生成日期包============================================
//                String uniqueDateCode = NumberUtils.getRandomValue(4);
//                //包体数据
//                byte[] bodyDateBytes = protocolAnalysis.packWriteParam(uniqueDateCode, "0804", dateData);
//                //包头数据
//                byte[] headerDateBytes = protocolAnalysis.packPackageHeader("10", bodyDateBytes.length);
//                //数据包
//                byte[] packageDateBytes = TypeConvertUtils.concatBytes(headerDateBytes, bodyDateBytes);
//                //=======================生成时间包==============================================
//                String uniqueTimeCode = NumberUtils.getRandomValue(4);
//                //包体数据
//                byte[] bodyTimeBytes = protocolAnalysis.packWriteParam(uniqueTimeCode, "0808", timeData);
//                //包头数据
//                byte[] headerTimeBytes = protocolAnalysis.packPackageHeader("10", bodyTimeBytes.length);
//                //数据包
//                byte[] packageTimeBytes = TypeConvertUtils.concatBytes(headerTimeBytes, bodyTimeBytes);
//                //生成日期和时间下行帧
//                byte[] downFrameBytes = protocolAnalysis.createDownFrame(stationId, packageDateBytes, packageTimeBytes);
//
//                List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                        .filter(a -> stationId.equals(a.get("StationCode").toString())).collect(Collectors.toList());
//                //下发数据
//                Socket socket = null;
//                if (filterStation.size() > 0) {
//                    socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//                }
//                String sendResult = MainObject.tcpServer.sendData(socket, downFrameBytes);
//                if (true == sendResult.equals("0")) {
//                    return "分站已离线，操作未下发";
//                }
//
//                MainObject.WRITE_PARAM_SEND_RECEIVER_MAP.put(uniqueTimeCode, null);
//
//                //===========================数据库记录时钟同步信息===================================
//                HashMap<String, Object> downStationMap = new HashMap<>();
//                String uniqueId = StringUtils.getUUID32();
//                downStationMap.put("ID", uniqueId);
//                downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.ClockSync.getIndex());
//                downStationMap.put("ContentDetail", stationId + "号分站时钟同步");
//                downStationMap.put("CreateTime", new Date());
//                downStationInfoMapper.insertDownStationInfo(downStationMap);
//                //====================================================================================
//
//                //时间计数器
//                int timeNum = 0;
//                //循环读取返回值
//                while (true) {
//                    Thread.sleep(1000);
//                    //读取写参数包
//                    UpWriteParametersPackage paramPackage = MainObject.WRITE_PARAM_SEND_RECEIVER_MAP.get(uniqueTimeCode);
//
//                    //如果小于2秒且状态为成功
//                    if (timeNum < 20
//                            && paramPackage != null) {
//
//                        //===========================数据库记录时钟同步信息===================================
//                        HashMap<String, Object> successMap = new HashMap<>();
//                        successMap.put("ID", uniqueId);
//                        successMap.put("ReceiveResult", paramPackage.getResult());
//                        successMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(successMap);
//                        //====================================================================================
//
//                        //移除该键
//                        MainObject.WRITE_PARAM_SEND_RECEIVER_MAP.remove(uniqueTimeCode);
//                        return paramPackage.getResult();
//                    }
//                    //如果大于2秒
//                    if (timeNum >= 20) {
//
//                        //===========================数据库记录时钟同步信息===================================
//                        HashMap<String, Object> failureMap = new HashMap<>();
//                        failureMap.put("ID", uniqueId);
//                        failureMap.put("ReceiveResult", "操作超时或失败");
//                        failureMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(failureMap);
//                        //====================================================================================
//
//                        //移除该键
//                        MainObject.WRITE_PARAM_SEND_RECEIVER_MAP.remove(uniqueTimeCode);
//                        return "操作超时或失败";
//                    }
//                    timeNum++;
//                }
//            };
//            //根据代码段实例创建一个未来任务
//            FutureTask<String> future = new FutureTask<String>(myCallable);
//            //运行任务
//            future.run();
//
//            Map<String, Object> resultMap = new HashMap<>();
//            resultMap.put("result", future.get());
//
//            return resultMap;
//        } catch (Exception ex) {
//            return null;
//        }
//    }
//
//    /**
//     * 读取分站参数信息 todo
//     *
//     * @param stationId    分站ID
//     * @param startAddress 起始地址
//     * @param dataLength   数据长度
//     * @param stationParam 填充的参数实体
//     * @return
//     */
//    @Override
//    public Map<String, Object> readStationParam(String stationId, String startAddress, int dataLength, Object stationParam) {
//        try {
//            Callable myCallable = (Callable<Object>) () -> {
//                //根据分站ID过滤分站信息
//                List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                        .filter(a -> stationId.equals(a.get("ID").toString())).collect(Collectors.toList());
//                //分站编号
//                String stationCode = "";
//                if (filterStation.size() > 0) {
//                    stationCode = filterStation.get(0).get("StationCode").toString();
//                }
//                //=========================生成读参数数据包======================================
//                String uniqueBaseCode = NumberUtils.getRandomValue(4);
//                //包体数据
//                byte[] bodyBaseBytes = protocolAnalysis.packReadParam(uniqueBaseCode, startAddress, dataLength);
//                //包头数据
//                byte[] headerBaseBytes = protocolAnalysis.packPackageHeader("03", bodyBaseBytes.length);
//                //数据包
//                byte[] packageBaseBytes = TypeConvertUtils.concatBytes(headerBaseBytes, bodyBaseBytes);
//
//                //生成分站基本参数下行帧
//                byte[] downFrameBytes = protocolAnalysis.createDownFrame(stationCode, packageBaseBytes);
//                //下发数据
//                Socket socket = null;
//                if (filterStation.size() > 0) {
//                    socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//                }
//                String sendResult = MainObject.tcpServer.sendData(socket, downFrameBytes);
//                if (true == sendResult.equals("0")) {
//                    HashMap<String, Object> failureMap = new HashMap<>();
//                    failureMap.put("ReceiveResult", "分站已离线，操作未下发");
//                    failureMap.put("ResultContent", null);//返回内容
//                    failureMap.put("ReceiveTime", new Date());
//                    return failureMap;
//                }
//
//                MainObject.READ_PARAM_SEND_RECEIVER_MAP.put(uniqueBaseCode, null);
//
//                //===================================================================================
//                HashMap<String, Object> downStationMap = new HashMap<>();
//                String uniqueId = StringUtils.getUUID32();
//                downStationMap.put("ID", uniqueId);
//                downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.ReadStationBase.getIndex());
//                downStationMap.put("ContentDetail", stationCode + "号分站参数读取信息");
//                downStationMap.put("CreateTime", new Date());
//                downStationInfoMapper.insertDownStationInfo(downStationMap);
//                //====================================================================================
//
//                //时间计数器
//                int timeNum = 0;
//                //循环读取返回值
//                while (true) {
//                    Thread.sleep(1000);
//                    //读取读参数包
//                    UpReadParamPackage paramPackage = MainObject.READ_PARAM_SEND_RECEIVER_MAP.get(uniqueBaseCode);
//
//                    //如果小于2秒且状态为成功
//                    if (timeNum < 20
//                            && paramPackage != null) {
//
//                        //===========================数据库记录信息===================================
//                        HashMap<String, Object> successMap = new HashMap<>();
//                        int dataContentLength = paramPackage.dataContent.length;
//                        int errorCode = TypeConvertUtils.bytesToReverseInt(paramPackage.dataContent);
//                        //如果数据长度等于1，则返回错误码
//                        if (dataContentLength == 1) {
//                            successMap.put("ReceiveResult", MainObject.ERROR_CODE_DESCRIPTION.get(errorCode));
//                            successMap.put("ResultContent", null);
//                        } else {
//                            successMap.put("ReceiveResult", "操作成功");
//                            //解析基本参数
//                            JavaStruct.unpack(stationParam, paramPackage.dataContent, ByteOrder.LITTLE_ENDIAN);
//                            successMap.put("ResultContent", stationParam);//返回内容
//                        }
//                        successMap.put("ID", uniqueId);
//                        successMap.put("ReceiveTime", new Date());
//
//                        downStationInfoMapper.updateDownStationInfo(successMap);
//                        //移除该键
//                        MainObject.READ_PARAM_SEND_RECEIVER_MAP.remove(uniqueBaseCode);
//                        return successMap;
//                    }
//                    //如果大于2秒
//                    if (timeNum >= 20) {
//
//                        //===========================数据库记录时钟同步信息===================================
//                        HashMap<String, Object> failureMap = new HashMap<>();
//                        failureMap.put("ID", uniqueId);
//                        failureMap.put("ReceiveResult", "操作超时或失败");
//                        failureMap.put("ResultContent", null);//返回内容
//                        failureMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(failureMap);
//                        //====================================================================================
//
//                        //移除该键
//                        MainObject.READ_PARAM_SEND_RECEIVER_MAP.remove(uniqueBaseCode);
//                        return failureMap;
//                    }
//                    timeNum++;
//                }
//            };
//            //根据代码段实例创建一个未来任务
//            FutureTask<Object> future = new FutureTask<Object>(myCallable);
//            //运行任务
//            future.run();
//            HashMap<String, Object> returnMap = (HashMap<String, Object>) future.get();
//            Map<String, Object> resultMap = new HashMap<>();
//            resultMap.put("ReceiveResult", returnMap.get("ReceiveResult"));
//            resultMap.put("ResultContent", returnMap.get("ResultContent"));
//            return resultMap;
//        } catch (Exception ex) {
//            ex.printStackTrace();
//            return null;
//        }
//    }
//
//    /**
//     * 下发分站地址写指令  todo
//     *
//     * @param stationId    分站编号
//     * @param startAddress 下发起始地址
//     * @param dataContent  下发内容
//     * @return
//     */
//    @Override
//    public Map<String, Object> writeStationParam(String stationId, String startAddress, int dataContent) {
//        try {
//            Callable myCallable = (Callable<String>) () -> {
//                //根据分站ID过滤分站信息
//                List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                        .filter(a -> stationId.equals(a.get("ID").toString())).collect(Collectors.toList());
//                //分站编号
//                String stationCode = "";
//                if (filterStation.size() > 0) {
//                    stationCode = filterStation.get(0).get("StationCode").toString();
//                }
//
//                //=======================生成下发内容==========================================
//
//                byte[] contentBytes = TypeConvertUtils.intToConverseBytes(dataContent, 4);
//                //===============================================================================
//                //=========================生成写入数据============================================
//                String uniqueCode = NumberUtils.getRandomValue(4);
//                //包体数据
//                byte[] bodyDateBytes = protocolAnalysis.packWriteParam(uniqueCode, startAddress, contentBytes);
//                //包头数据
//                byte[] headerDateBytes = protocolAnalysis.packPackageHeader("10", bodyDateBytes.length);
//                //数据包
//                byte[] packageDateBytes = TypeConvertUtils.concatBytes(headerDateBytes, bodyDateBytes);
//
//                //生成日期和时间下行帧
//                byte[] downFrameBytes = protocolAnalysis.createDownFrame(stationCode, packageDateBytes);
//                //下发数据
//                Socket socket = null;
//                if (filterStation.size() > 0) {
//                    socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//                }
//                String sendResult = MainObject.tcpServer.sendData(socket, downFrameBytes);
//                if (true == sendResult.equals("0")) {
//                    return "分站已离线，操作未下发";
//                }
//
//                MainObject.WRITE_PARAM_SEND_RECEIVER_MAP.put(uniqueCode, null);
//
//                //===========================数据库记录时钟同步信息===================================
//                HashMap<String, Object> downStationMap = new HashMap<>();
//                String uniqueId = StringUtils.getUUID32();
//                downStationMap.put("ID", uniqueId);
//                downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.WriteStationBase.getIndex());
//                downStationMap.put("ContentDetail", stationCode + "号分站写入参数");
//                downStationMap.put("CreateTime", new Date());
//                downStationInfoMapper.insertDownStationInfo(downStationMap);
//                //====================================================================================
//
//                //时间计数器
//                int timeNum = 0;
//                //循环读取返回值
//                while (true) {
//                    Thread.sleep(1000);
//                    //读取写参数包
//                    UpWriteParametersPackage paramPackage = MainObject.WRITE_PARAM_SEND_RECEIVER_MAP.get(uniqueCode);
//
//                    //如果小于2秒且状态为成功
//                    if (timeNum < 20
//                            && paramPackage != null) {
//
//                        //===========================数据库记录信息==========================================
//                        HashMap<String, Object> successMap = new HashMap<>();
//                        successMap.put("ID", uniqueId);
//                        successMap.put("ReceiveResult", paramPackage.getResult());
//                        successMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(successMap);
//                        //====================================================================================
//
//                        //移除该键
//                        MainObject.WRITE_PARAM_SEND_RECEIVER_MAP.remove(uniqueCode);
//                        return paramPackage.getResult();
//                    }
//                    //如果大于2秒
//                    if (timeNum >= 20) {
//
//                        //===========================数据库记录时钟同步信息===================================
//                        HashMap<String, Object> failureMap = new HashMap<>();
//                        failureMap.put("ID", uniqueId);
//                        failureMap.put("ReceiveResult", "操作超时或失败");
//                        failureMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(failureMap);
//                        //====================================================================================
//
//                        //移除该键
//                        MainObject.WRITE_PARAM_SEND_RECEIVER_MAP.remove(uniqueCode);
//                        return "操作超时或失败";
//                    }
//                    timeNum++;
//                }
//            };
//            //根据代码段实例创建一个未来任务
//            FutureTask<String> future = new FutureTask<String>(myCallable);
//            //运行任务
//            future.run();
//
//            Map<String, Object> resultMap = new HashMap<>();
//            resultMap.put("result", future.get());
//
//            return resultMap;
//        } catch (Exception ex) {
//            return null;
//        }
//    }
//
//    /**
//     * 标识卡模式切换
//     *
//     * @param stationID      分站ID
//     * @param startCardDeviceCode 标识卡起始ID
//     * @param endCardDeviceCode 标识卡终止ID
//     * @param mode           模式类型    1：仓储模式，2：定位模式
//     * @return
//     */
//    public Map<String, Object> cardModeChange(String stationID, String startCardDeviceCode,
//                                              String endCardDeviceCode, String mode) {
//        try {
//            Callable myCallable = (Callable<String>) () -> {
//                //根据分站ID过滤分站信息
//                List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                        .filter(a -> stationID.equals(a.get("ID").toString())).collect(Collectors.toList());
//                //分站编号
//                String stationCode = "";
//                if (filterStation.size() > 0) {
//                    stationCode = filterStation.get(0).get("StationCode").toString();
//                }
//
//                String uniqueCode = NumberUtils.getRandomValue(4);
//                //包体数据
//                byte[] bodyBytes = protocolAnalysis.packModeChangeData(uniqueCode, startCardDeviceCode,endCardDeviceCode, mode);
//                //包头数据
//                byte[] headerBytes = protocolAnalysis.packPackageHeader("15", bodyBytes.length);
//                //数据包
//                byte[] packageBytes = TypeConvertUtils.concatBytes(headerBytes, bodyBytes);
//
//                //生成模式切换下行帧
//                byte[] downFrameBytes = protocolAnalysis.createDownFrame(stationCode, packageBytes);
//
////                String uniqueCodeTemp = NumberUtils.getRandomValue(4);
////                //包体数据
////                byte[] bodyBytesTemp = protocolAnalysis.packCardModeChangeCancel(uniqueCodeTemp);
////                //包头数据
////                byte[] headerBytesTemp = protocolAnalysis.packPackageHeader("16", bodyBytesTemp.length);
////                //数据包
////                byte[] packageBytesTemp = TypeConvertUtils.concatBytes(headerBytesTemp, bodyBytesTemp);
////
////                //生成模式切换取消包下行帧
////                byte[] downFrameBytesTemp = protocolAnalysis.createDownFrame(stationCode, packageBytesTemp);
//
//
//
//                //下发数据
//                Socket socket = null;
//                if (filterStation.size() > 0) {
//                    socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//                }
//
////                String sendResultTemp = MainObject.tcpServer.sendData(socket, downFrameBytesTemp);
////                if (true == sendResultTemp.equals("0")) {
////                    return "分站已离线，操作未下发";
////                }
////
////                Thread.sleep(2000);
//
//                String sendResult = MainObject.tcpServer.sendData(socket, downFrameBytes);
//                if (true == sendResult.equals("0")) {
//                    return "分站已离线，操作未下发";
//                }
//
//                MainObject.MODE_CHANGE_SEND_RECEIVER_MAP.put(uniqueCode, null);
//
//                //===========================数据库记录时钟同步信息===================================
//                HashMap<String, Object> downStationMap = new HashMap<>();
//                String uniqueId = StringUtils.getUUID32();
//                downStationMap.put("ID", uniqueId);
//                downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.CardModeChange.getIndex());
//                downStationMap.put("ContentDetail", stationCode + "号分站下，发送卡设备编号" + startCardDeviceCode + "的模式为" + (mode.equals("1") ? "仓储模式" : "定位模式"));
//                downStationMap.put("CreateTime", new Date());
//                downStationInfoMapper.insertDownStationInfo(downStationMap);
//                //====================================================================================
//
//                //时间计数器
//                int timeNum = 0;
//                //循环读取返回值
//                while (true) {
//                    Thread.sleep(1000);
//                    //卡模式切换上行包
//                    UpCardModeChangePackage paramPackage = MainObject.MODE_CHANGE_SEND_RECEIVER_MAP.get(uniqueCode);
//
//                    //如果小于2秒且状态为成功
//                    if (timeNum < 20
//                            && paramPackage != null) {
//
//                        //===========================数据库记录信息==========================================
//                        HashMap<String, Object> successMap = new HashMap<>();
//                        successMap.put("ID", uniqueId);
//                        successMap.put("ReceiveResult", paramPackage.getResult());
//                        successMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(successMap);
//                        //====================================================================================
//
//                        //移除该键
//                        MainObject.MODE_CHANGE_SEND_RECEIVER_MAP.remove(uniqueCode);
//                        return paramPackage.getResult();
//                    }
//                    //如果大于2秒
//                    if (timeNum >= 20) {
//
//                        //===========================数据库记录时钟同步信息===================================
//                        HashMap<String, Object> failureMap = new HashMap<>();
//                        failureMap.put("ID", uniqueId);
//                        failureMap.put("ReceiveResult", "操作超时或失败");
//                        failureMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(failureMap);
//                        //====================================================================================
//
//                        //移除该键
//                        MainObject.MODE_CHANGE_SEND_RECEIVER_MAP.remove(uniqueCode);
//                        return "操作超时或失败";
//                    }
//                    timeNum++;
//                }
//            };
//            //根据代码段实例创建一个未来任务
//            FutureTask<String> future = new FutureTask<String>(myCallable);
//            //运行任务
//            future.run();
//
//            Map<String, Object> resultMap = new HashMap<>();
//            resultMap.put("result", future.get());
//
//            return resultMap;
//        } catch (Exception ex) {
//            return null;
//        }
//    }
//
//
//    /**
//     * 标识卡模式切换取消
//     *
//     * @param stationID  分站ID
//     * @return
//     */
//    public Map<String, Object> cardModeChangeCancel(String stationID){
//        try {
//            Callable myCallable = (Callable<String>) () -> {
//                //根据分站ID过滤分站信息
//                List<HashMap<String, Object>> filterStation = MainObject.STATION_INFO_LIST.stream()
//                        .filter(a -> stationID.equals(a.get("ID").toString())).collect(Collectors.toList());
//                //分站编号
//                String stationCode = "";
//                if (filterStation.size() > 0) {
//                    stationCode = filterStation.get(0).get("StationCode").toString();
//                }
//
//                String uniqueCodeTemp = NumberUtils.getRandomValue(4);
//                //包体数据
//                byte[] bodyBytesTemp = protocolAnalysis.packCardModeChangeCancel(uniqueCodeTemp);
//                //包头数据
//                byte[] headerBytesTemp = protocolAnalysis.packPackageHeader("16", bodyBytesTemp.length);
//                //数据包
//                byte[] packageBytesTemp = TypeConvertUtils.concatBytes(headerBytesTemp, bodyBytesTemp);
//
//                //生成模式切换取消包下行帧
//                byte[] downFrameBytesTemp = protocolAnalysis.createDownFrame(stationCode, packageBytesTemp);
//
//
//
//                //下发数据
//                Socket socket = null;
//                if (filterStation.size() > 0) {
//                    socket = MainObject.tcpServer.getIpAddressMapSocket().get(filterStation.get(0).get("IP"));
//                }
//
//                String sendResultTemp = MainObject.tcpServer.sendData(socket, downFrameBytesTemp);
//                if (true == sendResultTemp.equals("0")) {
//                    return "分站已离线，操作未下发";
//                }
//
//                MainObject.MODE_CHANGE_CANCEL_MAP.put(uniqueCodeTemp, null);
//
//                //===========================数据库记录时钟同步信息===================================
//                HashMap<String, Object> downStationMap = new HashMap<>();
//                String uniqueId = StringUtils.getUUID32();
//                downStationMap.put("ID", uniqueId);
//                downStationMap.put("CommandType", MainObject.StationCommandTypeEnum.CardModeChange.getIndex());
//                downStationMap.put("ContentDetail", stationCode + "号分站下，发送卡模式切换取消");
//                downStationMap.put("CreateTime", new Date());
//                downStationInfoMapper.insertDownStationInfo(downStationMap);
//                //====================================================================================
//
//                //时间计数器
//                int timeNum = 0;
//                //循环读取返回值
//                while (true) {
//                    Thread.sleep(1000);
//                    //卡模式切换上行包
//                    UpCardModeChangeCancelPackage paramPackage = MainObject.MODE_CHANGE_CANCEL_MAP.get(uniqueCodeTemp);
//
//                    //如果小于2秒且状态为成功
//                    if (timeNum < 20
//                            && paramPackage != null) {
//
//                        //===========================数据库记录信息==========================================
//                        HashMap<String, Object> successMap = new HashMap<>();
//                        successMap.put("ID", uniqueId);
//                        successMap.put("ReceiveResult", paramPackage.getResult());
//                        successMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(successMap);
//                        //====================================================================================
//
//                        //移除该键
//                        MainObject.MODE_CHANGE_CANCEL_MAP.remove(uniqueCodeTemp);
//                        return paramPackage.getResult();
//                    }
//                    //如果大于2秒
//                    if (timeNum >= 20) {
//
//                        //===========================数据库记录时钟同步信息===================================
//                        HashMap<String, Object> failureMap = new HashMap<>();
//                        failureMap.put("ID", uniqueId);
//                        failureMap.put("ReceiveResult", "操作超时或失败");
//                        failureMap.put("ReceiveTime", new Date());
//                        downStationInfoMapper.updateDownStationInfo(failureMap);
//                        //====================================================================================
//
//                        //移除该键
//                        MainObject.MODE_CHANGE_CANCEL_MAP.remove(uniqueCodeTemp);
//                        return "操作超时或失败";
//                    }
//                    timeNum++;
//                }
//            };
//            //根据代码段实例创建一个未来任务
//            FutureTask<String> future = new FutureTask<String>(myCallable);
//            //运行任务
//            future.run();
//
//            Map<String, Object> resultMap = new HashMap<>();
//            resultMap.put("result", future.get());
//
//            return resultMap;
//        } catch (Exception ex) {
//            return null;
//        }
//    }
//}
